var prefix = ctx + "manage/withdrawalRecord";
var prefixAdRecord = ctx + "manage/adRecord";
var prefixUserDailyActivity = ctx + "manage/userDailyActivity";

if (wrStatus === 1){
    $(function () {
        var options = {
            url: prefix + "/list",
            queryParams: queryParams,
            columns: [
                {
                    checkbox: true
                },
                {
                    field: 'usId',
                    title: '用户ID'
                },
                {
                    field: 'usNickname',
                    title: '用户名'
                },

                {
                    field: 'wrOrderId',
                    title: '订单ID'
                }, {
                    field: 'wrPayOrderId',
                    title: '支付订单ID'
                },
                {
                    field: 'wrName',
                    title: '姓名'
                },
                {
                    field: 'wrPhone',
                    title: '支付宝'
                },
                {
                    field: 'wrChannel',
                    title: '收款渠道',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '<span class="badge badge-success">支付宝</span>';
                        }
                        if (value === 2) {
                            return '<span class="badge badge-primary">微信</span>';
                        }
                    }
                },
                {
                    field: 'wrMoney',
                    title: '金额'
                },
                {
                    field: 'wrType',
                    title: '类型',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '<span class="badge badge-warning">金币</span>';
                        }
                        if (value === 2) {
                            return '<span class="badge badge-danger">红包</span>';
                        }
                        if (value === 3) {
                            return '<span class="badge badge-warning">金币佣金</span>';
                        }
                        if (value === 4) {
                            return '<span class="badge badge-danger">红包佣金</span>';
                        }
                        if (value === 5) {
                            return '<span class="badge badge-info">推广佣金</span>';
                        }
                    }
                },
                {
                    field: 'wrBeforeMoney',
                    title: '变更前金额'
                },
                {
                    field: 'wrAfterMoney',
                    title: '变更后金额'
                },
                {
                    field: 'wrStatus',
                    title: '审核状态',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '<span class="badge badge-success">审核中</span>';
                        }
                        if (value === 2) {
                            return '<span class="badge badge-primary">通过</span>';
                        }
                        if (value === 3) {
                            return '<span class="badge badge-danger">拒绝</span>';
                        }
                    }
                },
                {
                    field: 'wrMark',
                    title: '备注'
                },
                {
                    field: 'createTime',
                    title: '提现时间'
                },
                {
                    align: 'center',
                    title: '应用使用时长',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-sm" href="#" title="编辑" mce_href="#" onclick="queryWrithdrawalUse(\'' + row.id + '\')"><i>详细</i></a> ');
                        return actions.join('');
                    }
                },
                {
                    title: '广告记录',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-sm" href="#" title="编辑" mce_href="#" onclick="queryAdRecord(\'' + row.usId + '\')"><i>详细</i></a> ');
                        return actions.join('');
                    }
                },
                {
                    title: '设备环境',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-sm" href="#" title="编辑" mce_href="#" onclick="queryUserDaily(\'' + row.usId + '\')"><i>详细</i></a> ');
                        return actions.join('');
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        if (row.wrStatus === 2) {
                            return;
                        }
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-sm ' + editFlag + '" href="#" title="编辑" mce_href="#" onclick="edit(\'' + row.id + '\')"><i class="fa fa-edit"></i></a> ');
                        return actions.join('');
                    }
                }]
        };
        $.ryTable.init(options);
        var createTime = $('#createTime').val();
        _ajax_query(prefix + "/statistics", {
            wrStatus: wrStatus,
            startTime: createTime === '' ? '' : startCreatTime,
            endTime: createTime === '' ? '' : endTime
        }, callback);
    });
}
if (wrStatus === 3) {
    $(function () {
        var options = {
            url: prefix + "/list",
            queryParams: queryParams,
            columns: [
                {
                    checkbox: true
                },
                {
                    field: 'usId',
                    title: '用户ID'
                },
                {
                    field: 'usNickname',
                    title: '用户名'
                },

                {
                    field: 'wrOrderId',
                    title: '订单ID'
                }, {
                    field: 'wrPayOrderId',
                    title: '支付订单ID'
                },
                {
                    field: 'wrName',
                    title: '姓名'
                },
                {
                    field: 'wrPhone',
                    title: '支付宝'
                },
                {
                    field: 'wrChannel',
                    title: '收款渠道',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '<span class="badge badge-success">支付宝</span>';
                        }
                        if (value === 2) {
                            return '<span class="badge badge-primary">微信</span>';
                        }
                    }
                },
                {
                    field: 'wrMoney',
                    title: '金额'
                },
                {
                    field: 'wrType',
                    title: '类型',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '<span class="badge badge-warning">金币</span>';
                        }
                        if (value === 2) {
                            return '<span class="badge badge-danger">红包</span>';
                        }
                        if (value === 3) {
                            return '<span class="badge badge-warning">金币佣金</span>';
                        }
                        if (value === 4) {
                            return '<span class="badge badge-danger">红包佣金</span>';
                        }
                        if (value === 5) {
                            return '<span class="badge badge-info">推广佣金</span>';
                        }
                    }
                },
                {
                    field: 'wrBeforeMoney',
                    title: '变更前金额'
                },
                {
                    field: 'wrAfterMoney',
                    title: '变更后金额'
                },
                {
                    field: 'wrStatus',
                    title: '审核状态',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '<span class="badge badge-success">审核中</span>';
                        }
                        if (value === 2) {
                            return '<span class="badge badge-primary">通过</span>';
                        }
                        if (value === 3) {
                            return '<span class="badge badge-danger">拒绝</span>';
                        }
                    }
                },
                {
                    field: 'wrMark',
                    title: '备注'
                },
                {
                    field: 'refuseTime',
                    title: '拒绝时间'
                },
                {
                    align: 'center',
                    title: '应用使用时长',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-sm" href="#" title="编辑" mce_href="#" onclick="queryWrithdrawalUse(\'' + row.id + '\')"><i>详细</i></a> ');
                        return actions.join('');
                    }
                },
                {
                    title: '广告记录',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-sm" href="#" title="编辑" mce_href="#" onclick="queryAdRecord(\'' + row.usId + '\')"><i>详细</i></a> ');
                        return actions.join('');
                    }
                },
                {
                    title: '设备环境',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-sm" href="#" title="编辑" mce_href="#" onclick="queryUserDaily(\'' + row.usId + '\')"><i>详细</i></a> ');
                        return actions.join('');
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        if (row.wrStatus === 2) {
                            return;
                        }
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-sm ' + editFlag + '" href="#" title="编辑" mce_href="#" onclick="edit(\'' + row.id + '\')"><i class="fa fa-edit"></i></a> ');
                        return actions.join('');
                    }
                }]
        };
        $.ryTable.init(options);
        var createTime = $('#createTime').val();
        _ajax_query(prefix + "/statistics", {
            wrStatus: wrStatus,
            startTime: createTime === '' ? '' : startCreatTime,
            endTime: createTime === '' ? '' : endTime
        }, callback);
    });
}
if (wrStatus === 2) {
    $(function () {
        var options = {
            url: prefix + "/list",
            queryParams: queryParams,
            columns: [
                {
                    checkbox: true
                },
                {
                    field: 'usId',
                    title: '用户ID'
                },
                {
                    field: 'usNickname',
                    title: '用户名'
                },

                {
                    field: 'wrOrderId',
                    title: '订单ID'
                }, {
                    field: 'wrPayOrderId',
                    title: '支付订单ID'
                },
                {
                    field: 'wrName',
                    title: '姓名'
                },
                {
                    field: 'wrPhone',
                    title: '支付宝'
                },
                {
                    field: 'wrChannel',
                    title: '收款渠道',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '<span class="badge badge-success">支付宝</span>';
                        }
                        if (value === 2) {
                            return '<span class="badge badge-primary">微信</span>';
                        }
                    }
                },
                {
                    field: 'wrMoney',
                    title: '金额'
                },
                {
                    field: 'wrType',
                    title: '类型',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '<span class="badge badge-warning">金币</span>';
                        }
                        if (value === 2) {
                            return '<span class="badge badge-danger">红包</span>';
                        }
                        if (value === 3) {
                            return '<span class="badge badge-warning">金币佣金</span>';
                        }
                        if (value === 4) {
                            return '<span class="badge badge-danger">红包佣金</span>';
                        }
                        if (value === 5) {
                            return '<span class="badge badge-info">推广佣金</span>';
                        }
                    }
                },
                {
                    field: 'wrBeforeMoney',
                    title: '变更前金额'
                },
                {
                    field: 'wrAfterMoney',
                    title: '变更后金额'
                },
                {
                    field: 'wrStatus',
                    title: '审核状态',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '<span class="badge badge-success">审核中</span>';
                        }
                        if (value === 2) {
                            return '<span class="badge badge-primary">通过</span>';
                        }
                        if (value === 3) {
                            return '<span class="badge badge-danger">拒绝</span>';
                        }
                    }
                },
                {
                    field: 'wrMark',
                    title: '备注'
                },
                {
                    field: 'updateTime',
                    title: '审核时间'
                },
                {
                    align: 'center',
                    title: '应用使用时长',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-sm" href="#" title="编辑" mce_href="#" onclick="queryWrithdrawalUse(\'' + row.id + '\')"><i>详细</i></a> ');
                        return actions.join('');
                    }
                },
                {
                    title: '广告记录',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-sm" href="#" title="编辑" mce_href="#" onclick="queryAdRecord(\'' + row.usId + '\')"><i>详细</i></a> ');
                        return actions.join('');
                    }
                },
                {
                    title: '设备环境',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-sm" href="#" title="编辑" mce_href="#" onclick="queryUserDaily(\'' + row.usId + '\')"><i>详细</i></a> ');
                        return actions.join('');
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        if (row.wrStatus === 2) {
                            return;
                        }
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-sm ' + editFlag + '" href="#" title="编辑" mce_href="#" onclick="edit(\'' + row.id + '\')"><i class="fa fa-edit"></i></a> ');
                        return actions.join('');
                    }
                }]
        };
        $.ryTable.init(options);
        var createTime = $('#createTime').val();
        _ajax_query(prefix + "/statistics", {
            wrStatus: wrStatus,
            startTime: createTime === '' ? '' : startCreatTime,
            endTime: createTime === '' ? '' : endTime
        }, callback);
    });
}

function queryParams(params) {
    var createTime = $('#createTime').val();
    return {
        // 传递参数查询参数
        pageSize: params.limit,
        pageNum: params.offset / params.limit + 1,
        searchValue: params.search,
        usId: $("#usId").val(),
        nickname: $("#usNickname").val(),
        wrOrderId: $("#wrOrderId").val(),
        startWrMoney: $("#startWrMoney").val(),
        endWrMoney: $("#endWrMoney").val(),
        wrPhone: $("#wrPhone").val(),
        wrName: $("#wrName").val(),
        wrType: $("#wrType option:selected").val(),
        wrStatus: wrStatus,
        startTime: createTime === '' ? '' : startCreatTime,
        endTime: createTime === '' ? '' : endTime
    };
}

/*奖励记录-搜索*/
function search() {
    $('.bootstrap-table').bootstrapTable('refresh', queryParams);
    var createTime = $('#createTime').val();
    var params = {
        // 传递参数查询参数
        usId: $("#usId").val(),
        nickname: $("#usNickname").val(),
        wrOrderId: $("#wrOrderId").val(),
        wrType: $("#wrType option:selected").val(),
        wrStatus: wrStatus,
        startWrMoney: $("#startWrMoney").val(),
        endWrMoney: $("#endWrMoney").val(),
        wrPhone: $("#wrPhone").val(),
        wrName: $("#wrName").val(),
        startTime: createTime === '' ? '' : startCreatTime,
        endTime: createTime === '' ? '' : endTime
    };
    _ajax_query(prefix + "/statistics", params, callback);
}

function callback(result) {
    $('label#userGoldCoin').text("金币金额：" + result.userGoldCoin);
    $('label#userRedPacket').text("红包金额：" + result.userRedPacket);
    $('label#moneyCommissionGoldCoins').text("金币佣金：" + result.moneyCommissionGoldCoins);
    $('label#moneyCommissionRedEnvelope').text("红包佣金：" + result.moneyCommissionRedEnvelope);
    $('label#moneyExtensionRedEnvelope').text("推广佣金：" + result.moneyExtensionRedEnvelope);
}

/*提现记录-修改*/
function edit(id) {
    var url = prefix + '/edit/' + id;
    layer_showAuto("审核提现", url);
}

function queryAdRecord(id) {
    var url = prefixAdRecord + '/' + id;
    layer_showAuto("广告记录详细", url);
}

function queryUserDaily(id) {
    var url = prefixUserDailyActivity + "/my/" + id;
    layer_showAuto("风控日志详细", url);
}

function queryWrithdrawalUse(id) {
    var url = prefix + "/use/" + id;
    layer_showAuto("应用使用时长", url);
}
